package com.ruoyi.mall.app.service.impl;


import com.ruoyi.mall.app.domain.DtsBrands;
import com.ruoyi.mall.app.domain.DtsCart;
import com.ruoyi.mall.app.mapper.DtsCartMapper;
import com.ruoyi.mall.app.service.DtsCartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Description TODO
 * @Author 李琪
 * @Date 2025/4/1 16:06
 **/
@Service
public class DtsCartServiceImpl implements DtsCartService {

    @Autowired
    private DtsCartMapper dtsCartMapper;

    @Override
    public List<DtsBrands> selectCartBrands(DtsCart dtsCart) {
        return dtsCartMapper.selectCartBrands(dtsCart);
    }

    @Override
    public int deleteCartByUserId(Long Id) {
        return dtsCartMapper.deleteCartByUserId(Id);
    }

    @Override
    public int deleteCartByUserIds(Long[] ids) {
        return dtsCartMapper.deleteCartByUserIds(ids);
    }

    @Override
    public int updateCartByUserId(Long Id, Long number) {
        return dtsCartMapper.updateCartByUserId(Id,number);
    }


    @Override
    public int addCart(DtsCart dtsCart) {
        DtsCart dtsCart1 = dtsCartMapper.selectCartByGoods(dtsCart);
        if(dtsCart1!=null){
            return dtsCartMapper.updateCartByUserId(dtsCart1.getId(),dtsCart1.getNumber() + dtsCart.getNumber());
        }
        return dtsCartMapper.addCart(dtsCart);
    }
}
